#include "system.h"
#include "gd32e23x.h"

void SystemSetInterruptGroup(uint32_t PriorityGroup)
{
}

uint32_t SystemGetClkFreq(SYSTEM_CLK_E clock, SYSTEM_CLK_FREQ_UNIT_E unit)
{
	uint32_t clk;
	
	switch (clock) {
		case SYSTEM_CLK_SYS:
			clk = rcu_clock_freq_get(CK_SYS);
			break;
		case SYSTEM_CLK_AHB:
			clk = rcu_clock_freq_get(CK_AHB);
			break;
		case SYSTEM_CLK_APB1:
			clk = rcu_clock_freq_get(CK_APB1);
			break;
		case SYSTEM_CLK_APB2:
			clk = rcu_clock_freq_get(CK_APB2);
			break;
		case SYSTEM_CLK_ADC:
			clk = rcu_clock_freq_get(CK_ADC);
			break;
		case SYSTEM_CLK_USART0:
			clk = rcu_clock_freq_get(CK_USART);
			break;
		default:
			return 0;
	}
	
	switch (unit) {
		case SYSTEM_CLK_UNIT_HZ:
			break;
		case SYSTEM_CLK_UNIT_KHZ:
			clk = clk / 1000;
			break;
		case SYSTEM_CLK_UNIT_MHZ:
			clk = clk / 1000000;
			break;
		default:
			break;
	}
	
	return clk;
}

SYSTEM_CLK_SORCE_E SystemGetClkSource(void)
{
	uint32_t source = rcu_system_clock_source_get();
	
	if (source == 0x00) {
		return SYSTEM_CLK_SOURCE_IRC8M;
	}
	else if (source == 0x01) {
		return SYSTEM_CLK_SOURCE_HXTAL;
	}
	else if (source == 0x02) {
		return SYSTEM_CLK_SOURCE_PLL;
	}
	else {
		return SYSTEM_CLK_SOURCE_NULL;
	}
}
